package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/5.
 */
@HttpInlet(Conn.SHOW_SHOW_VIEW)
public class GoodsInfoGet extends BaseAsyGet<GoodsInfoGet.GoodsInfoEntity> {

    public String id, user_id, type = "1",region_id;

    public GoodsInfoGet(AsyCallBack<GoodsInfoEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected GoodsInfoEntity parser(JSONObject object) throws Exception {

        if(object.optInt("code")==200){

            JSONObject jsonObject = object.optJSONObject("info");

            GoodsInfoEntity goodsInfoEntity = new GoodsInfoEntity();

            goodsInfoEntity.id = jsonObject.optString("id");
            goodsInfoEntity.title = jsonObject.optString("title");
            goodsInfoEntity.picurl = jsonObject.optString("picurl");
            goodsInfoEntity.start_time = jsonObject.optString("start_time");
            goodsInfoEntity.end_time = jsonObject.optString("end_time");
            goodsInfoEntity.placeid = jsonObject.optString("placeid");
            goodsInfoEntity.is_seat = jsonObject.optString("is_seat");
            goodsInfoEntity.price_high = jsonObject.optString("price_high");
            goodsInfoEntity.price_low = jsonObject.optString("price_low");
            goodsInfoEntity.status = jsonObject.optString("status");
            goodsInfoEntity.productid = jsonObject.optString("productid");

            goodsInfoEntity.delivery_way=jsonObject.optString("delivery_way");

            goodsInfoEntity.place_name = jsonObject.optString("place_name");
            goodsInfoEntity.place_address = jsonObject.optString("place_address");
            goodsInfoEntity.comment_number = jsonObject.optString("comment_number");
            goodsInfoEntity.collect = jsonObject.optString("collect");
            goodsInfoEntity.place_lat = jsonObject.optDouble("place_lat");
            goodsInfoEntity.place_lng = jsonObject.optDouble("place_lng");
            goodsInfoEntity.classid = jsonObject.optString("classid");
            goodsInfoEntity.media = jsonObject.optString("media");

            JSONArray jsonArray = object.optJSONArray("GuessYouLike");

            for (int i = 0; i < jsonArray.length(); i++) {

                JSONObject jsonObject_data = jsonArray.optJSONObject(i);

                GoodsInfoLikeEntity goodsInfoLikeEntity = new GoodsInfoLikeEntity();
                goodsInfoLikeEntity.id = jsonObject_data.optString("id");
                goodsInfoLikeEntity.title = jsonObject_data.optString("title");
                goodsInfoLikeEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject_data.optString("picurl");
                goodsInfoLikeEntity.start_time = jsonObject_data.optString("start_time");
                goodsInfoLikeEntity.is_seat = jsonObject_data.optString("is_seat");
                goodsInfoLikeEntity.price_low = jsonObject_data.optString("price_low");
                goodsInfoLikeEntity.price_high = jsonObject_data.optString("price_high");
                goodsInfoLikeEntity.status = jsonObject_data.optString("status");
                goodsInfoLikeEntity.place_name = jsonObject_data.optString("place_name");
                goodsInfoLikeEntity.skiptype = jsonObject_data.optString("skiptype");

                goodsInfoEntity.guessYouLike.add(goodsInfoLikeEntity);

            }

            return goodsInfoEntity;

        }

        TOAST = object.optString("message");

        return null;
    }

    public static class GoodsInfoEntity implements Serializable {

        public String id, title, picurl, start_time, end_time, classid, placeid, is_seat, price_low, price_high, status, productid, place_name, place_address, comment_number, collect, media
                ,delivery_way

                ;
        public double place_lat, place_lng;
        public List<GoodsInfoLikeEntity> guessYouLike = new ArrayList<>();

    }

    public static class GoodsInfoLikeEntity implements Serializable {

        public String id, title, picurl, start_time, is_seat, price_low, price_high, status, place_name, skiptype;

    }

}
